//
//  RTImage+Extension.swift
//  Weibo
//
//  Created by Brisinga on 16/3/14.
//  Copyright © 2016年 Root. All rights reserved.
//

import UIKit

extension UIImage {

    func scaleToWidth(width: CGFloat) -> UIImage {
    
        if self.size.width <= 600 {
            
            return self
        }
        
        let height = width / self.size.width * self.size.height
        
        let rect = CGRectMake(0, 0, width, height)
        
        UIGraphicsBeginImageContext(rect.size)
        
        self.drawInRect(rect)
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image
    }

}
